import UIKit
import Flutter
import agora_rtc_engine

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    
    private var customCaptureAudioPlugin: CustomCaptureAudioPlugin!
    
    override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        let controller : FlutterViewController = window?.rootViewController as! FlutterViewController

        customCaptureAudioPlugin = CustomCaptureAudioPlugin()
        
        // The `CustomAudioSourceApiSetup` is generated by [pigeon](https://pub.dev/packages/pigeon), you can see the
        // the definiton on `example/lib/examples/advanced/custom_capture_audio/custom_capture_audio_api.dart`
        CustomCaptureAudioApiSetup(
        controller.binaryMessenger, customCaptureAudioPlugin)

        // Register the `CustomAudioPlugin` to interect with the `AgoraRtcEngineKit`
        RtcEnginePluginRegistrant.register(customCaptureAudioPlugin)
          
        GeneratedPluginRegistrant.register(with: self)
          
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    override func applicationWillTerminate(_ application: UIApplication) {
        RtcEnginePluginRegistrant.unregister(customCaptureAudioPlugin)
    }
}
